package xyz.xxpc.springcloud.consumer.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Discovery {
    private DiscoveryClient client;

    @Autowired
    public void setClient(DiscoveryClient client) {
        this.client = client;
    }

    @RequestMapping("/discovery")
    public List<ServiceInstance> show(){
        // 获取所有的服务
        List<String> services = client.getServices();
        System.out.println("服务列表:" + services);

        // 获取provider-30080这个服务的信息
        List<ServiceInstance> instances = client.getInstances("PROVIDER-30080");
        return instances;
    }
}
